
#include <threadpool.h>
#include <string>
#include <chrono>
#include <iostream>

int func(int value) {
    std::cout << __FUNCTION__ << " execute.-->" << std::this_thread::get_id() << std::endl;
    return value * 1000;
}

std::string func2(std::string str, int value) {
    std::cout << __FUNCTION__ << " execute.-->" << std::this_thread::get_id() << std::endl;
    return str + std::to_string(value);
}

void show(std::string str, double value) {
    std::cout << __FUNCTION__ << " execute.-->" << std::this_thread::get_id() << std::endl;
    std::cout << "show: " << str << " " << value << std::endl;
}

int main(int argc, char *argv[]) {
    class F {
    public:
        double operator()(double value) {
            std::cout << "F{}() execute.-->" << std::this_thread::get_id() << std::endl;
            return value * 1000;
        }
    };

    auto lambda = [](int value) {
        std::cout << "lambda execute.-->" << std::this_thread::get_id() << std::endl;
        return value * 20;
    };
    threadpool thrdpool;
    auto ret = thrdpool.submit(lambda, 45);
    auto ret2 = thrdpool.submit(F(), 3.1415);
    auto fr = thrdpool.submit(func, 14);
    auto fr2 = thrdpool.submit(func2, "f2", 14);
    auto showr = thrdpool.submit(show, "f2", 23.25);

    for (int i = 0; i < 40; ++i) {
        thrdpool.submit([i]() {
            //static std::mutex mutex;
            //std::lock_guard<std::mutex> lg(mutex);
            for (int j = 0; j < 1; j++)
                std::cout << "lambda" << i << " execute.-->" << std::this_thread::get_id() << std::endl;
            // std::this_thread::sleep_for(std::chrono::milliseconds(1000));
            return 20;
        });
    }

    for (int i = 0; i < 1000; i++) {
        thrdpool.submit([&](){
            for (int i = 0; i < 40; i++) {
                thrdpool.submit([i]() {
                    //static std::mutex mutex;
                    //std::lock_guard<std::mutex> lg(mutex);
                    for (int j = 0; j < 1; j++)
                        std::cout << "lambda" << i << " execute.-->" << std::this_thread::get_id() << std::endl;
                    std::this_thread::sleep_for(std::chrono::milliseconds(10));
                    return 20;
                });
            }
        });
    }

    class W {
    public:
        int f(double i) {
            std::cout << "W::f\n";
            return 0;
        }
    };
    W w;
    thrdpool.submit(&W::f, w, 10.9);
    thrdpool.submit(&W::f, &w, 10.9);

    //auto t = ret.get();
    //std::cout << t << std::endl;
    //std::cout << ret2.get() << std::endl;
    //std::cout << fr.get() << std::endl;
    //std::cout << fr2.get() << std::endl;
    //showr.wait();
    return 0;
}
